﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TLSharp;

public partial class MakeNote : System.Web.UI.Page
{
    public string CookieUserName = "";
    public string CookiePassword = "";
    public string AppGuid = System.Configuration.ConfigurationSettings.AppSettings["AppGuid"];

    protected void Page_Load(object sender, EventArgs e)
    {
        int GameID = System.Convert.ToInt32(Request["GameID"]);
        int OwnedTeamID = System.Convert.ToInt32(Request["OwnedTeamID"]);
        int ReplyToNoteID = (Request["ReplyToNoteID"]!=null && Request["ReplyToNoteID"].Length>0? System.Convert.ToInt32(Request["ReplyToNoteID"]): -1);
        CookieUserName = Request.Cookies["TLUsername"] != null ? Request.Cookies["TLUsername"].Value : "";
        CookiePassword = Request.Cookies["TLPassword"] != null ? Request.Cookies["TLPassword"].Value : "";
        string Note = (Request["Note"] != null && Request["Note"].Length > 0 ? Request["Note"] : "");
        bool bPrivate = (Request["bPrivate"]!=null && Request["bPrivate"]=="on" ? true : false);
        
            if (Request["Mode"] != null && Request["Mode"]=="Submit")
            {
               

                //process the move
                //Configure this link to direct the user to the site in twitter messages
                    string RetrievalLink = Server.UrlEncode("http://YourGame.com/Game.aspx?bStartPage=true&GameID=" + GameID.ToString());
                    string PrivateTeamList = "";
                    if (bPrivate)
                    {
                        PrivateTeamList = OwnedTeamID.ToString();
                    }
                    TouchLeagueService.SetGameNote(CookieUserName,CookiePassword,AppGuid,GameID,ReplyToNoteID,Note,bPrivate,PrivateTeamList, RetrievalLink);

                    //redirect
                    Response.Redirect("Game.aspx?GameID=" + GameID.ToString());
                
            }
            System.Text.StringBuilder ResponseText = new System.Text.StringBuilder();

            //build the reply form

            ResponseText.Append(@"<form id='ReplyForm' method='post' class='panel' action='MakeNote.aspx?Mode=Submit'>");
        bool bReply = false;
        if(Request["ReplyToNoteID"]!=null && Request["ReplyToNoteID"].Length>0)
        {
             ResponseText.Append(@"<h2>Reply:</h2>");
            bReply=true;
        }
        else
        {
             ResponseText.Append(@"<h2>Make A New Note:</h2>");

        }
        ResponseText.Append(@"<fieldset>      
        <input type='hidden' value='" + GameID.ToString() + @"' name='GameID'>
        <input type='hidden' value='" + OwnedTeamID.ToString() + @"' name='OwnedTeamID'>");
        if (bReply)
        {
            ResponseText.Append(@"<input type='hidden' value='" + ReplyToNoteID.ToString() + @"' name='ReplyToNoteID'>");
        }

 ResponseText.Append(@"<div class='row'>
<label>Message:</label>  
<br /><br />
            <textarea type='text'   id='Note' name='Note' cols='40' rows='5'></textarea></div>
<div class='row'>
<label>My eyes only?:</label>  

            <input type='checkbox' class='toggle' name='bPrivate' id='bPrivate' " + (bPrivate ? "checked" : "") + @" /></div>
            </fieldset>
            <fieldset>
            <input class='button blueButton' type='submit' value='Submit'/>
            </fieldset>                    
                    </form>
                    ");
                
            
            Response.Write(ResponseText.ToString());
            Response.End();
        

    }

    
} 
